What is cookie-signature?
The cookie-signature package is used to sign and unsign values using a secret key, typically for use in cookie values to prevent tampering. It provides a simple API for signing and verifying strings.
What are cookie-signature's main functionalities?
Sign
This feature allows you to sign a value using a secret key. The result is a signed value that can be used in a cookie or other transport method. The signature is appended to the value with a 's:' prefix.
"signature = require('cookie-signature');\nsignedValue = signature.sign('value', 'secret');"
Unsign
This feature allows you to unsign a previously signed value using the same secret key. If the signature is valid, the original value is returned. If the signature is invalid, a false value is returned, indicating potential tampering.
"signature = require('cookie-signature');\nunsignedValue = signature.unsign('signedValue', 'secret');"
Other packages similar to cookie-signature
jsonwebtoken
jsonwebtoken (or JWT) is a package that allows you to encode and decode JSON Web Tokens, which are an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This package provides more complex features like token expiration, audience, issuer validation, and more, compared to the simpler cookie-signature package.
secure-cookie
secure-cookie is a package that provides cookie signing and encryption. It offers additional security by encrypting the cookie value, which cookie-signature does not do. secure-cookie is a good choice if you need to protect sensitive information in cookies beyond just preventing tampering.
keygrip
keygrip is a package for signing and verifying data (like cookies) but with support for key rotation. It allows you to use an array of keys for signing and will verify signatures against any of the provided keys. This is useful for applications that need to rotate secrets without invalidating existing signatures, which is not a feature provided by cookie-signature.
cookie-signature
Sign and unsign cookies.
Example
var cookie = require('cookie-signature');
var val = cookie.sign('hello', 'tobiiscool');
val.should.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI');
var val = cookie.sign('hello', 'tobiiscool');
cookie.unsign(val, 'tobiiscool').should.equal('hello');
cookie.unsign(val, 'luna').should.be.false;
License
MIT.
See LICENSE file for details.